var page = {};
function createOrderMenuDiv(goodsNo){
  page.goodsNo = goodsNo;
  new Ext.Panel({
		renderTo:"orderMenuDiv",
		title:"订单明细操作",
		width:500,
		layout:"form",
		hideLabels:false,
		labelAlign:"right",
		defaultType: 'textfield',
		items:[
		{fieldLabel:"请输入姓名<font color='red'>*</font>",id:"buyerName",name:"buyerName",labelStyle:"margin-top:10px",style:"margin-top:10px;width:300px"},
		{fieldLabel:"请输入地址<font color='red'>*</font>",id:"buyerAddress",xtype:"textarea",name:"buyerAddress",labelStyle:"margin-top:10px",style:"margin-top:10px;width:300px"},
		{fieldLabel:"请输入电话<font color='red'>*</font>",id:"buyerPhone",name:"buyerPhone",labelStyle:"margin-top:10px",style:"margin-top:10px;width:300px"},
		{fieldLabel:"请输入Email<font color='red'>*</font>",id:"buyerEmail",name:"buyerEmail",labelStyle:"margin-top:10px",style:"margin-top:10px;width:300px"}
		],
		buttons:[
		  {text:"保存",handler:function(){saveOrderInfo(function(){createOrderData();});}},
		  {text:"关闭",handler:function(){clickGoodsNavi();}}
		] 
	  }
    );
}

//创建订单
function createOrderData(){
   var orderNo = $("#orderNo").val();
   load("contentDiv","orderInfor.html",false,function(){
      createOrderInfo(orderNo);
   });
}

//保存订单信息
function saveOrderInfo(callBack){
   var reCat = /\s/g;
   var buyerName = $("#buyerName").val();
   buyerName = buyerName.replace(reCat,"");
   var buyerAddress = $("#buyerAddress").val();
   buyerAddress = buyerAddress.replace(reCat,"");
   var buyerPhone = $("#buyerPhone").val();
   buyerPhone = buyerPhone.replace(reCat,"");
   var buyerEmail = $("#buyerEmail").val();
   buyerEmail = buyerEmail.replace(reCat,"");
   var warnMsg = "";
   
   if(buyerName == ""){
      warnMsg = warnMsg + "姓名栏目不能为空<br/>";
   }
   
   if(buyerAddress == ""){
       warnMsg = warnMsg + "地址栏目不能为空<br/>";
   }
   if(buyerPhone == ""){
       warnMsg = warnMsg + "电话栏目不能为空<br/>";
   }
   if(buyerEmail == ""){
       warnMsg = warnMsg + "Email栏目不能为空<br/>";
   }
   if(warnMsg != ""){
     showMessage(warnMsg,"error");
     return;
   }
   realSaveOrderInfo(buyerName,buyerAddress,buyerPhone,buyerEmail,callBack);
   
}
//保存订单信息
function realSaveOrderInfo(buyerName,buyerAddress,buyerPhone,buyerEmail,callBack){
    if(page.goodsNo){
       //如果page.goodsNo存在，则将当前商品加入购物车库中
       addGoodsToCart(page.goodsNo);
    }
    var param = "orderMenuVO.buyerName=" + buyerName + "&orderMenuVO.buyerAddress=" + buyerAddress + "&orderMenuVO.buyerPhone=" + buyerPhone + "&orderMenuVO.buyerEmail=" + buyerEmail;
    $.ajax({
        url:"saveOrderInfo.action",
        type:"POST",
        data:param,
        async: false,
        success:function(result){
           var orderNo = result;
           $("#orderNo").val(orderNo);
           if(callBack){
              callBack();
           }
        }
    });
}